
package org.vasil.jouikov.service

import javax.servlet.ServletConfig
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import javax.servlet.annotation.WebServlet;

@WebServlet("/upload")
class HttpReceive extends HttpServlet {

    def void init(ServletConfig config) {
	super.init(config)
    }

    protected def void process(request, response) {

        def json = new StringBuilder("Hello World!"),
        ex = getString(request.getParameter('ex'), '')
        json << " ex=$ex"

        response.setContentType("text/html;charset=UTF-8")
        def out = response.getWriter()
        out.write(json as String)
        out.close()
    }

    private String getString(value, deff) {
        return value ? value as String : deff
    }

    protected def void doGet(HttpServletRequest request, HttpServletResponse response) {
        process(request, response)
    }
    protected def void doPost(HttpServletRequest request, HttpServletResponse response) {
        process(request, response)
    }
    String getServletInfo() {
        return "Update Orders";
    }
}

